export default {
  data () {
    return {
      indicator: [
        {key: 'elevatorMaxNum', value: '升降机'},
        {key: 'environmentMaxNum', value: '环境'},
        {key: 'towercraneMaxNum', value: '塔吊'},
        {key: 'videocatchMaxNum', value: '视频监控'},
        {key: 'violationMaxNum', value: '违规'}
      ],
      todayNum: ['elevatorTodayNum', 'environmentTodayNum', 'towercraneTodayNum', 'videocatchTodayNum', 'violationTodayNum'],
      avgNum: ['elevatorAvgNum', 'environmentAvgNum', 'towercraneAvgNum', 'videocatchAvgNum', 'violationAvgNum'],
      maxNum: ['elevatorMaxNum', 'environmentMaxNum', 'towercraneMaxNum', 'videocatchMaxNum', 'violationMaxNum'],
      todayStartOption: {
        tooltip: {
          backgroundColor: 'rgba(9, 37, 56, 0.5)',
          extraCssText: 'box-shadow: 0 0 5px 2px rgba(8, 69, 69) inset;'
        },
        legend: {
          right: 0,
          top: 40,
          itemWidth: 8,
          itemHeight: 8,
          orient: 'vertical',
          textStyle: {
            color: '#a8c5ed'
          },
          itemGap: 20,
          padding: [0, 0, 0, 0],
          data: [{name: '今日报警', icon: 'circle'}, {name: '7天日均值', icon: 'circle'}, {name: '最多报警', icon: 'circle'}]
        },
        radar: {
          center: ['35%', '58.5%'],
          nameGap: 10,
          axisLine: {
            show: false
          },
          splitLine: {
            lineStyle: {
              color: '#22495c'
            }
          },
          splitArea: {
            show: false
          },
          name: {
            textStyle: {
              color: '#a8c5ed'
            }
          },
          indicator: []
        },
        series: [{
          name: 'warning',
          type: 'radar',
          data: [
            {
              value: [],
              color: '#00eaff',
              lineStyle: {
                color: '#00eaff'
              },
              areaStyle: {
                color: 'rgba(0, 234, 255, 0.3)'
              },
              itemStyle: {
                color: '#00eaff',
                opacity: 0
              },
              name: '今日报警'
            },
            {
              value: [],
              color: '#ffc600',
              lineStyle: {
                color: '#ffc600'
              },
              areaStyle: {
                color: 'rgba(253, 197, 1, 0.3)'
              },
              itemStyle: {
                color: '#ffc600',
                opacity: 0
              },
              name: '7天日均值'
            },
            {
              value: [],
              color: '#f33f3f',
              lineStyle: {
                color: '#f33f3f'
              },
              areaStyle: {
                color: 'rgba(243, 63, 63, 0.3)'
              },
              itemStyle: {
                color: '#f33f3f',
                opacity: 0
              },
              name: '最多报警'
            }
          ]
        }]
      }
    }
  },
  methods: {
    initTodayStartg () {
      this.todayStartOption.radar.indicator = []
      this.todayStartOption.series[0].data[0].value = []
      this.todayStartOption.series[0].data[1].value = []
      this.todayStartOption.series[0].data[2].value = []
      let maxArr = []
      for (let item of this.maxNum) {
        if (this.todayAlarm.rardaData[item]) {
          maxArr.push(this.todayAlarm.rardaData[item])
        } else {
          maxArr.push(0)
        }
      }
      let maxAllArr = []
      for (let item in this.todayAlarm.rardaData) {
        maxAllArr.push(this.todayAlarm.rardaData[item])
      }
      let maxAllNumber = Math.max(...maxAllArr) + 2
      for (let item of this.indicator) {
        this.todayStartOption.radar.indicator.push({
          name: item.value,
          max: maxAllNumber
        })
      }
      for (let item of this.todayNum) {
        let todayAlarm = 0
        if (this.todayAlarm.rardaData[item]) {
          todayAlarm = this.todayAlarm.rardaData[item]
        }
        this.todayStartOption.series[0].data[0].value.push(todayAlarm)
      }
      for (let item of this.avgNum) {
        let todayAlarm = 0
        if (this.todayAlarm.rardaData[item]) {
          todayAlarm = this.todayAlarm.rardaData[item]
        }
        this.todayStartOption.series[0].data[1].value.push(todayAlarm)
      }
      this.todayStartOption.series[0].data[2].value = maxArr
      if (!this.todayStartOptionEchart) {
        this.todayStartOptionEchart = this.$echarts.init(this.$refs.warningTodayStart)
      }
      this.todayStartOptionEchart.setOption(this.todayStartOption)
    }
  }
}
